/*
 * 
 */
package messageAPI;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;

/**
 * The Class Configuration. Note that this is currently just a placeholder until the settings file can be used successfully.
 */
public class Configuration {

	/**
	 * Sets the properties of in the settings file.
	 */
	public static void setProperties()
	{
		
		//This is hard coded to save a bit of time. Obviously this is not the ideal way to do it.
    	Properties prop = new Properties();
    	 
    	try {
    		
    		//set the properties value
    		prop.setProperty("Server", "localhost");
    		prop.setProperty("ExchangeName", "logs");
    		prop.setProperty("ExchangeTypeName", "direct");
    		prop.setProperty("isDurable", "true");
    		prop.setProperty("autoAck", "true");
    		prop.setProperty("QUEUE_NAME", "hello");
    		
    		//save properties to project root folder
    		prop.store(new FileOutputStream("config.properties"), null);
 
    	} catch (IOException ex) {
    		ex.printStackTrace();
        }
    }
		
		/**
		 * Gets the properties stored in the settings file.
		 *
		 * @param properties the properties
		 * @return the map
		 */
		public static Map<String, String> GetProperties(List<String> properties)
		{
			Properties prop = new Properties();
		
			Map<String, String> propertyMap = new HashMap<String, String>();
			
			try {
		           //load a properties file
				prop.load(new FileInputStream("config.properties"));
				
				 for(String item : properties)
				 {
					 String value=prop.getProperty(item);
					 if(value!=null)
					 {
						 propertyMap.put(item, value);
					 }
				 }
				} catch (IOException ex) {
					ex.printStackTrace();
			    }
			return propertyMap;
		}
}
